package com.hengxinguotong.zhihuichengjian.utils;

import android.annotation.SuppressLint;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

@SuppressLint("SimpleDateFormat")
public class TimeUtils {

	@SuppressLint("SimpleDateFormat") 
	public static String getCurrentTime(){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Date date=new Date();
		String time=sdf.format(date);
		return time;
	}

	public static String getCurrentMonth(){
		SimpleDateFormat sdf=new SimpleDateFormat("MM");
		Date date=new Date();
		String time=sdf.format(date);
		return time;
	}

	public static String getCurrentYear(){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy");
		Date date=new Date();
		String time=sdf.format(date);
		return time;
	}
	
	public static String EnglishToChinese(String date){
		SimpleDateFormat sdf1=new SimpleDateFormat("MMM d, yyyy hh:mm:ss a",  
                Locale.ENGLISH);
		SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date date1=sdf1.parse(date);
			String date2=sdf2.format(date1);
			return date2;
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return "";
	}
	
	public static String getHours(String date){
		SimpleDateFormat sdf=new SimpleDateFormat("MMM d, yyyy hh:mm:ss a",  
                Locale.ENGLISH);
		try {
			Date former=sdf.parse(date);
			Date current=new Date();
			long durring=current.getTime()-former.getTime();
			int hours=(int) (durring/3600000);
			int minutes=(int) ((durring%3600000)/60000);
			return hours+"小时"+minutes+"分钟";
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return "";
	}

	public static String getDate(){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		Date date=new Date();
		String time=sdf.format(date);
		return time;
	}
	
	public static String getDetailsDate(){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmm");
		Date date=new Date();
		String time=sdf.format(date);
		return time;
	}

	public static String getDetailDate(){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddHHmmssSSSS");
		Date date=new Date();
		String time=sdf.format(date);
		return time;
	}
	
	public static String getStringDate(String date){
		SimpleDateFormat sdf=new SimpleDateFormat("MMM d, yyyy hh:mm:ss a",  
                Locale.ENGLISH);
		SimpleDateFormat sdf1=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date dateTemp = sdf.parse(date);
			return sdf1.format(dateTemp);
			
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return "";
	}
	
	public static long getLeftTime(String updateTime,String curentTime ,String leftTime){
		SimpleDateFormat sdf1=new SimpleDateFormat("MMM d, yyyy hh:mm:ss a",  
                Locale.ENGLISH);
		SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date date1=sdf1.parse(updateTime);
			Date date2=sdf2.parse(curentTime);
			long lefttime=date1.getTime()+Long.parseLong(leftTime)*1000-date2.getTime();
			if(lefttime>=0){
				return lefttime;
//			}else{
//				return 0;
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return 0;
	}
	
	public static String getCurentTime(){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date=new Date();
		String curentTime=sdf.format(date);
		return curentTime;
	}
}
